package Java实训.第七天字符流;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Task2 {
    /*
     * 通过字符流实现文件拷贝效果
     * */
    public static void main(String[] args) {
        FileReader fr = null;
        FileWriter fw = null;
        try {
            fr = new FileReader("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\task-20221125.txt");
            fw = new FileWriter("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\task2.txt");
            int len;
            char[] chars = new char[1024];
            while ((len = fr.read(chars)) != -1) {
                fw.write(chars, 0, len);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (Exception e) {
                   e.printStackTrace();
                }
            }
            if (fr != null){
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
